<template>
<!-- 提现申请 -->
  <div class="withdraw">
    <el-dialog
      :visible.sync="isShow"
      width="40%"
      center
      :before-close="handleClose">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px">
        <el-form-item label="提现金额" prop="money" >
          <el-input v-model.number="ruleForm.money" :placeholder="frozenCoin"></el-input>
        </el-form-item>
        <!-- <div class='prompt'>
          <span>
            <span class='el-blue'> {{ frozenCoin }}</span>
          </span>
        </div> -->
        <!-- <el-form-item label="备注" prop="comment">
          <el-input  v-model="ruleForm.comment"></el-input>
        </el-form-item> -->

      </el-form>
      <span slot="footer" class="dialog-footer">
        <!-- <el-button @click="handleClose">取 消</el-button> -->
        <el-button type="primary" v-no-more-click:3000 @click="submit('ruleForm')">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data () {
    var validateMoney = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入提现金额'));
      } else {
        if (!Number(value)) {
          callback(new Error('请输入正确的金额'));
        } else if (value <= 0) {
          callback(new Error('提现金额必须大于0'));
        } else {
          callback()
        }
      }

    }
    return {
      isShow: false,
      ruleForm: {
        money: null,
        comment: ''
      },
      rules: {
        money: [
          { validator: validateMoney, trigger: 'blur' }
        ]
      },
      frozenCoin: ''
    }
  },
  methods: {
    show (data) {
      this.isShow = true
      // this.ruleForm.money = pCoin

      this.frozenCoin = `有${data.frozenCoin}元不可提现`
    },
    submit (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.submitPost()
          this.isShow = false
        } else {
          return false
        }
      });
    },
    submitPost () {
      let params = {
        money: this.ruleForm.money
      }
      if (this.ruleForm.comment != '') {
        params.comment = this.ruleForm.comment
      }
      this.$axios.post('api/drawing', params).then(res => {
        if (res.data.code == 200) {
          this.$message({
            type: 'success',
            message: "发起提现成功"
          })
          this.$emit('refresh')
          this.handleClose()
        } else if (res.data.code == 400) {
          this.$message.error(res.data.message)
        }
      }).catch(err => {

      })
    },
    handleClose () {
      this.isShow = false
      this.$refs['ruleForm'].resetFields()
    }
  }
}
</script>

<style lang='less' type='text/css'>
  .withdraw {
    .el-form {
      .prompt {
        font-size: 12px;
        margin: 0 0 10px 100px ;
      }
    }
    .dialog-footer {
      .el-button {
        background:rgba(88,165,234,1);
        padding: 8px 30px;
        border-color:rgba(88,165,234,1); 
        color:rgba(254,254,254,1);
        font-size: 15px;
      }
    }
  }
  
</style>
